/*    */ package cc.s2m.web.s2mBlog.controller;
/*    */ 
/*    */ import cc.s2m.util.CookieUtil;
/*    */ import cc.s2m.web.s2mBlog.controller.base.BaseController;
/*    */ import cc.s2m.web.s2mBlog.util.MemcacheKeys;
/*    */ import cc.s2m.web.s2mBlog.util.StaticProp;
/*    */ import com.google.code.kaptcha.Producer;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.io.IOException;
/*    */ import javax.imageio.ImageIO;
/*    */ import javax.servlet.ServletOutputStream;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ import net.spy.memcached.MemcachedClient;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ 
/*    */ @Controller
/*    */ public class PicCode extends BaseController
/*    */ {
/*    */ 
/*    */   @Autowired
/*    */   private Producer captchaProducer;
/*    */ 
/*    */   @Autowired
/*    */   private MemcachedClient memcachedClient;
/*    */ 
/*    */   @RequestMapping(value={"/code"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*    */   public void code(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException
/*    */   {
/* 37 */     response.setDateHeader("Expires", 0L);
/*    */ 
/* 39 */     response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
/*    */ 
/* 42 */     response.addHeader("Cache-Control", "post-check=0, pre-check=0");
/*    */ 
/* 44 */     response.setHeader("Pragma", "no-cache");
/*    */ 
/* 46 */     response.setContentType("image/jpeg");
/*    */ 
/* 48 */     String capText = this.captchaProducer.createText();
/*    */ 
/* 51 */     saveCode(request, response, capText);
/*    */ 
/* 54 */     BufferedImage bi = this.captchaProducer.createImage(capText);
/*    */ 
/* 56 */     ServletOutputStream out = response.getOutputStream();
/*    */ 
/* 59 */     ImageIO.write(bi, "jpg", out);
/* 60 */     out.flush();
/* 61 */     out.close();
/*    */   }
/*    */ 
/*    */   public void saveCode(HttpServletRequest request, HttpServletResponse response, String capText)
/*    */   {
/* 74 */     CookieUtil cookie = new CookieUtil(request, response);
/* 75 */     String cookieId = cookie.getCookie(StaticProp.cookieID);
/* 76 */     if ((cookieId == null) || (cookieId.trim().isEmpty())) {
/* 77 */       cookieId = request.getSession(true).getId();
/* 78 */       cookie.setCookie(StaticProp.cookieID, cookieId, Integer.valueOf(-1), null);
/*    */     }
/* 80 */     this.memcachedClient.set(MemcacheKeys.PIC_CODE.getKey() + cookieId, 300, capText);
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.controller.PicCode
 * JD-Core Version:    0.6.1
 */